clear
set type double
set more 1

***************************************
*NOTES
*Online appendix table B3 - robustness of export currency choice
*********************************************************************

capture log using log/OnlineAppendixTableB3_xchoice_robust.log, replace

use ../../rawdata/world_bank/wb_country_indicators, clear
	rename iso2 cty_code
	collapse (mean) cpi_infl gdp_growth gdp_percap, by(cty_code)
save temp/world_bank, replace

*main product at hs4
use ../../rawdata/X_2019, clear
	append using ../../rawdata/X_2018
	append using ../../rawdata/X_2017
	gen hs4=substr(cncode,1,4)
	destring hs4, replace
	gen hs6=substr(cncode,1,6)
	gcollapse (sum) value, by(vat hs4)
	egen tot=sum(value), by(vat)
	gen sh=value/tot
	bys vat (sh): egen maxsh=max(sh)
	gen main=sh==maxsh
	keep if main==1
	drop if sh<=0.6
	keep vat hs4
save temp/main, replace


use ../data/xcurrencychoice_estdata, clear

**********************************
*merge on additional data
	merge m:1 cty_code using temp/world_bank, keep(match master) nogen
	merge m:1 vat hs4 using temp/main, keep(match master) 
	gen main=_merge==3
	drop _merge

	merge m:1 hs6 using ../data/Rauch_hs6_concordance, keep(match master) 
	gen dif=con=="n" if _merge==3
	drop _merge
	merge m:1 cty_code using ../data/usd_peg, keep(match master) nogen
	merge m:1 cty_code using ../data/exports_country, keep(match master) nogen
	merge m:1 hs4 using ../data/exports_HS4, keep(match master) nogen
	
	gen lngdp_percap=ln(gdp_percap)	

*merge in additional variables
*firm-level variables
	merge m:1 vat using ../data/Additional_Variables, keep(match master) nogen
	replace coverage=coverage/100
	replace shRD=0 if missing(shRD)
	gen lnassets=ln(tot_assets)

*********************************************************
*ESTIMATION
***********************************************
*Additional robustness
*******************************************

*col 1: dif
	eststo: reghdfe Ix mphi_xeu lnmemp ms if dif==1, absorb(cp date) cluster(vat)

*col 2: nondif
	eststo: reghdfe Ix mphi_xeu lnmemp ms if dif==0, absorb(cp date) cluster(vat)


*col 3: main product
	eststo: reghdfe Ix mphi_xeu lnmemp ms if main==1, absorb(cp date) cluster(vat)

*col 4: just one month 2017:06 with industry and country (if it was industryXcountry then it would be analogous to having industryXcountryXdate
	eststo: reghdfe Ix mphi_xeu lnmemp ms if date==ym(2017,6), absorb(cty_code hs4) cluster(vat)


*no country-time fe
*****************************
*one country variable at a time
foreach var in usd_peg cpi_infl lngdp_percap lnexports_c lnexports_hs4 {	

	eststo: reghdfe Ix mphi_xeu lnmemp ms `var', absorb(date) cluster(vat)

	}

*included for reference
	eststo: reghdfe Ix , absorb(date) cluster(vat)
	eststo: reghdfe Ix mphi_xeu lnmemp ms , absorb(date) cluster(vat)


esttab using "../results/AppendixTableB3_xchoice.csv", se  b(3) se(3) r2 ar2 star(* 0.10 ** 0.05 *** 0.01) compress replace
eststo clear



log close
	
